import axios from 'axios';

// DeepSeek API 配置
const DEEPSEEK_API_KEY = 'sk-6f5dda506a104d338a91620166278d06';
const DEEPSEEK_BASE_URL = 'https://api.deepseek.com/chat/completions';

/**
 * 调用DeepSeek API的通用方法
 * @param {Array} messages - 对话消息数组，格式: [{role: 'user', content: '消息内容'}, ...]
 * @param {string} model - 模型名称，默认为'deepseek-chat'
 * @param {boolean} stream - 是否使用流式输出，默认为false
 * @returns {Promise} - 返回API响应结果
 */
export const callDeepSeekAPI = async (messages, model = 'deepseek-chat', stream = false) => {
  try {
    const response = await axios.post(
      DEEPSEEK_BASE_URL,
      {
        model,
        messages,
        stream
      },
      {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${DEEPSEEK_API_KEY}`
        }
      }
    );
    return response.data;
  } catch (error) {
    console.error('DeepSeek API调用失败:', error.response?.data || error.message);
    throw error;
  }
};

// 示例用法:
// callDeepSeekAPI([{role: 'user', content: '你好!'}])
//   .then(data => console.log(data))
//   .catch(err => console.error(err));